package com.yq.cp.utils.wechat.configuration;


import com.yq.cp.utils.wechat.handler.MiniAppHandler;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Log4j2
@Configuration
@ConditionalOnClass({
        MiniAppHandler.class
})
@EnableConfigurationProperties({
        MiniAppConfiguration.class,
        WeChatPaymentConfiguration.class
})
public class WeChatAutoConfiguration {

    @Resource
    private MiniAppConfiguration miniAppConfiguration;
    @Resource
    private WeChatPaymentConfiguration weChatPaymentConfiguration;

    @Bean
    @ConditionalOnMissingBean(MiniAppHandler.class)
    @ConditionalOnProperty(name = "nicosoft.wechat.miniapp.enable", havingValue = "true")
    public MiniAppHandler miniAppHandler() {
        log.info("Registered wechat miniapp support");
        return new MiniAppHandler(miniAppConfiguration);
    }


}
